package com.basic.business.shift.controller;


import java.util.List;
import java.io.IOException;
import org.springframework.security.access.prepost.PreAuthorize;
import javax.annotation.Resource;
import com.basic.common.annotation.FileExport;
import com.basic.common.utils.easyExcel.EasyExcelUtils;
import org.springframework.web.bind.annotation.*;
import com.basic.common.annotation.Log;
import com.basic.common.core.controller.BaseController;
import com.basic.common.core.domain.AjaxResult;
import com.basic.common.enums.BusinessType;
import com.basic.business.shift.domain.TShiftMgmt;
import com.basic.business.shift.service.ITShiftMgmtService;
import com.basic.common.core.page.TableDataInfo;

/**
 * 班次管理Controller
 * 
 * @author zhaoxy_jn@163.com
 */
@RestController
@RequestMapping("/business/shiftMgmt")
public class TShiftMgmtController extends BaseController
{
    @Resource
    private ITShiftMgmtService tShiftMgmtService;

    /**
     * 查询班次管理列表
     */
    @PreAuthorize("@ss.hasPermi('business:shiftMgmt:list')")
    @GetMapping("/list")
    public TableDataInfo list(TShiftMgmt tShiftMgmt)
    {
        startPage();
        List<TShiftMgmt> list = tShiftMgmtService.getList(tShiftMgmt);
        return getDataTable(list);
    }

    /**
     * 导出班次管理列表
     */
    @PreAuthorize("@ss.hasPermi('business:shiftMgmt:export')")
    @Log(title = "班次管理", businessType = BusinessType.EXPORT)
    @FileExport(fileName = "班次管理.xlsx")
    @PostMapping("/export")
    public String export(TShiftMgmt tShiftMgmt) throws IOException
    {
        List<TShiftMgmt> list = tShiftMgmtService.getList(tShiftMgmt);
        return EasyExcelUtils.excelExport(TShiftMgmt.class,"班次管理数据", list);
    }

    /**
     * 获取班次管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:shiftMgmt:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(tShiftMgmtService.get(id));
    }

    /**
     * 新增班次管理
     */
    @PreAuthorize("@ss.hasPermi('business:shiftMgmt:add')")
    @Log(title = "班次管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TShiftMgmt tShiftMgmt)
    {
        return toAjax(tShiftMgmtService.insert(tShiftMgmt));
    }

    /**
     * 修改班次管理
     */
    @PreAuthorize("@ss.hasPermi('business:shiftMgmt:edit')")
    @Log(title = "班次管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TShiftMgmt tShiftMgmt)
    {
        return toAjax(tShiftMgmtService.update(tShiftMgmt));
    }

    /**
     * 删除班次管理
     */
    @PreAuthorize("@ss.hasPermi('business:shiftMgmt:remove')")
    @Log(title = "班次管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tShiftMgmtService.deleteByIds(ids));
    }

    /**
     * 刷新缓存
     */
    @PreAuthorize("@ss.hasPermi('business:shiftMgmt:refreshCache')")
    @Log(title = "班次管理", businessType = BusinessType.CLEAN)
    @DeleteMapping("/refreshCache")
    public AjaxResult refreshCache()
    {
        tShiftMgmtService.resetShiftCache();
        return success();
    }

    /**
     * 状态变更
     */
    @PreAuthorize("@ss.hasPermi('business:shiftMgmt:changeStatus')")
    @Log(title = "班次管理", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestParam("ids") String[] ids, @RequestParam("status") String status)
    {
        return toAjax(tShiftMgmtService.updateStatusByIds(ids, status));
    }

}
